package com.chookss.view;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chookss.HomeActivityss;
import com.chookss.R;
import com.chookss.home.document.DocumentDetailActivity;
import com.chookss.home.document.DocumentSearchActivity;
import com.chookss.home.entity.DocunmentEntity;
import com.chookss.tools.GlideUtils;
import com.chookss.video.VideoOnePlayActivity;
import com.chookss.video.entity.VideoEntity;
import com.chookss.video.recommend.VedioDetailActivity;

import butterknife.BindView;

public class ForScreenDialog extends BaseDialog {


    @BindView(R.id.tvInit)
    TextView tvInit;
    @BindView(R.id.ivVideo)
    ImageView ivVideo;
    @BindView(R.id.ivDocument)
    ImageView ivDocument;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvSure)
    TextView tvSure;
    @BindView(R.id.tvCancel)
    TextView tvCancel;
    private String type; // （1资料，2长视频，3短视频）
    private String resourceId;//资料code 或者视频id
    private VideoEntity videoEntity=null;
    private Context context;

    public ForScreenDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_for_screen;
    }

    @Override
    protected void init(View view) {
        initCenter(0.7f);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("1".equals(type)) {
                    Intent intentScan = new Intent(context, DocumentSearchActivity.class);
                    intentScan.putExtra("dataCode", resourceId);
                    intentScan.putExtra("type", 3);
                    context.startActivity(intentScan);
                } else if("3".equals(type)) {
                    if(videoEntity==null){
                        dismiss();
                        return;
                    }
                    Intent intent = new Intent(context, VideoOnePlayActivity.class);
                    intent.putExtra("watermark", "2");
                    intent.putExtra("video", videoEntity);
                    context.startActivity(intent);
                } else  if ("2".equals(type)){
                    if(videoEntity==null){
                        dismiss();
                        return;
                    }
                    Intent intent = new Intent(context, VedioDetailActivity.class);
                    intent.putExtra("watermark", "20");
                    intent.putExtra("video", videoEntity);
                    context.startActivity(intent);
                }
                dismiss();
            }
        });
    }

    public ForScreenDialog(@NonNull Context context, String type, VideoEntity videoEntity) {
        super(context);
        this.context = context;
        this.type = type;
        this.videoEntity = videoEntity;
        tvInit.setText("是否播放视频");
        tvTitle.setText(videoEntity.videoTitle);
        ivVideo.setVisibility(View.VISIBLE);
        GlideUtils.load(context,videoEntity.videoCoverPath,ivVideo,R.drawable.default_vedio);
    }

    public ForScreenDialog(@NonNull Context context, DocunmentEntity data) {
        super(context);
        this.context = context;
        this.type = "1";
        this.resourceId = data.getDataCode();
        tvInit.setText("是否查看资料");
        tvTitle.setText(data.getDataTitle());
        ivDocument.setVisibility(View.VISIBLE);
        if ("1".equals(data.getFileType())) {
            Glide.with(context).load(R.drawable.icon_preview_word).into(ivDocument);
        } else if ("2".equals(data.getFileType())) {
            Glide.with(context).load(R.drawable.icon_preview_excel).into(ivDocument);
        } else if ("3".equals(data.getFileType())) {
            Glide.with(context).load(R.drawable.icon_preview_ppt).into(ivDocument);
        } else if ("4".equals(data.getFileType())) {
            Glide.with(context).load(R.drawable.icon_preview_pdf).into(ivDocument);
        } else {
            Glide.with(context).load(R.drawable.icon_file_default).into(ivDocument);
        }
    }
}
